#include "Config.h"


#include "tinyxml.h"

CConfig::CConfig()
{
}


CConfig::~CConfig()
{
}

bool CConfig::LoadSetting()
{
	std::string strPath = GetAppPath();
	strPath += "MonitorService.cfg";

	TiXmlDocument	doc;
	if (!doc.LoadFile(strPath.c_str()))
		return FALSE;

	TiXmlElement*	pRoot = doc.RootElement();
	if (NULL == pRoot)
		return FALSE;


	if (!MonServiceCfgParser::XmlElement2MonSrvConfig(pRoot, _Moncfg))
		return false;

	
	return true;
}



bool CConfig::LoadModSetting()
{
	std::string  strFileName = GetAppPath() + "modules_monitor.xml";

	TiXmlDocument	doc;
	if (!doc.LoadFile(strFileName.c_str()))
		return false;

	TiXmlElement*	pRoot = doc.RootElement();
	if (NULL == pRoot)
		return false;

	const char*	sTag = pRoot->Value();
	if (NULL == sTag || _stricmp(sTag, "modules"))
		return false;

	TiXmlElement*	pModCfg = pRoot->FirstChildElement("module");
	while (pModCfg)
	{
		MOD_DLL_INFO mn_module = {0, "", "", "" };

		const char*	id = pModCfg->Attribute("id");
		if (id)
			mn_module._id = atoi(id);

		const char*	desc = pModCfg->Attribute("desc");
		if (desc)
			mn_module._desc = desc;

		const char*	dllfile = pModCfg->Attribute("dllfile");
		if (dllfile)
			mn_module._dllfile = dllfile;

		const char*	content = pModCfg->Attribute("content");
		if (content)
			mn_module._content = content;

		if (mn_module._desc != "")
			m_moniMapMOD[mn_module._desc] = mn_module;

		pModCfg = pModCfg->NextSiblingElement("module");
	}

	return true;
}
